var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(), e = 0, i = 0;

Page({
    data: {
        recordsList: [],
        focusBol: !0,
        roomList: [],
        dataInfo: "",
        id: "",
        playBackData: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        activeName: 0,
        videoList: [],
        activitys1: [],
        activitys2: [],
        titleArr: [],
        dataList: [],
        showLoading: !1,
        imgCount: 0
    },
    onLoad: function(t) {
        t.id && this.setData({
            id: t.id
        }), this.getData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        for (var t = 0; t < this.data.roomList.length; t++) this.data.roomList[t].clearTime && clearTimeout(this.data.roomList[t].clearTime);
    },
    onPullDownRefresh: function() {},
    onShareAppMessage: function() {},
    goPage: function(t) {
        var a = t.currentTarget.dataset.status, e = t.currentTarget.dataset.id;
        3 == a ? wx.navigateTo({
            url: "/packageD/directSeeding/livePage/livePage?id=" + e + "&playerType=live"
        }) : wx.navigateTo({
            url: "/packageD/directSeeding/foreshow/foreshow?id=" + e
        });
    },
    focusBtn: function() {
        this.data.focusBol ? this.addConcern() : this.cancelConcern();
    },
    changeTabs: function(t) {
        this.setData({
            activeName: t.currentTarget.dataset.index
        }), this.handleClick();
    },
    addConcern: function() {
        var t = this, e = a.getNetAddresss("plugin.room.frontend.anchor.concern");
        a._postNetWork({
            url: e,
            showToastIn: !1,
            data: {
                member_id: this.data.id
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), t.setData({
                    focusBol: !1
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    cancelConcern: function() {
        var t = this, e = a.getNetAddresss("plugin.room.frontend.anchor.cancel-concern");
        a._postNetWork({
            url: e,
            showToastIn: !1,
            data: {
                member_id: this.data.id
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? (wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                }), t.setData({
                    focusBol: !0
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    getData: function() {
        var t = this, e = a.getNetAddresss("plugin.room.frontend.anchor.get-anchor");
        a._postNetWork({
            url: e,
            showToastIn: !1,
            data: {
                member_id: this.data.id
            },
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    var i = e.data.room;
                    if (i && i.length > 0) for (var o = new Date().getTime(), s = 0; s < i.length; s++) {
                        var n = i[s].live_time, d = 1e3 * new Date(n).getTime();
                        i[s].day = "00", i[s].hou = "00", i[s].min = "00", i[s].sec = "00", o > d ? i[s].stop = !0 : (t._countDown(s, i[s].live_time), 
                        i[s].stop = !1);
                    } else i = [];
                    t.setData({
                        dataInfo: e.data,
                        roomList: i
                    }), console.log(t.data.roomList), 1 == t.data.dataInfo.is_concern && t.setData({
                        focusBol: !1
                    }), 1 == t.data.dataInfo.is_back && t.data.titleArr.push({
                        name: "live",
                        title: "直播回放",
                        url: "plugin.room.frontend.anchor.get-back"
                    }), e.data.short_video_display && t.data.titleArr.push({
                        name: "video",
                        title: "短视频",
                        url: "plugin.room.frontend.anchor.get-video"
                    }), t.setData({
                        titleArr: t.data.titleArr
                    }), t.data.titleArr.forEach(function(a, e) {
                        t.data.dataList.push({
                            isLoadMore: !0,
                            page: 1,
                            total_page: 0,
                            list: [],
                            url: a.url
                        });
                    }), t.handleClick();
                } else wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    _countDown: function(a, e) {
        var i, o = new Date().getTime(), s = 1e3 * new Date(e).getTime();
        if (s - o > 0) {
            var n, d = (s - o) / 1e3, r = parseInt(d / 86400), c = parseInt(d % 86400 / 3600), l = parseInt(d % 86400 % 3600 / 60), u = parseInt(d % 86400 % 3600 % 60);
            this.setData((t(n = {}, "roomList[" + a + "].day", this._timeFormat(r)), t(n, "roomList[" + a + "].hou", this._timeFormat(c)), 
            t(n, "roomList[" + a + "].min", this._timeFormat(l)), t(n, "roomList[" + a + "].sec", this._timeFormat(u)), 
            n));
        } else {
            var m;
            this.setData((t(m = {}, "roomList[" + a + "].day", "00"), t(m, "roomList[" + a + "].hou", "00"), 
            t(m, "roomList[" + a + "].min", "00"), t(m, "roomList[" + a + "].sec", "00"), t(m, "roomList[" + a + "].stop", !1), 
            m));
        }
        s - o < 0 ? this.setData((t(i = {}, "roomList[" + a + "].day", "00"), t(i, "roomList[" + a + "].hou", "00"), 
        t(i, "roomList[" + a + "].min", "00"), t(i, "roomList[" + a + "].sec", "00"), t(i, "roomList[" + a + "].stop", !1), 
        i)) : this.data.roomList[a].clearTime = setTimeout(this._countDown.bind(this, a, e), 1e3);
    },
    _timeFormat: function(t) {
        return t < 10 ? "0" + t : t;
    },
    handleClick: function() {
        var e = this;
        if (this.data.dataList[e.data.activeName].list.length > 0) e.data.isLoadMore = this.data.dataList[e.data.activeName].isLoadMore; else {
            var i = a.getNetAddresss(e.data.dataList[e.data.activeName].url);
            a._postNetWork({
                url: i,
                showToastIn: !1,
                data: {
                    page: 1,
                    member_id: this.data.id
                },
                success: function(a) {
                    var i, o = a.data;
                    1 == o.result ? (e.setData((t(i = {
                        isLoadMore: !0
                    }, "dataList[" + e.data.activeName + "].isLoadMore", !0), t(i, "dataList[" + e.data.activeName + "].total_page", o.data.last_page), 
                    t(i, "dataList[" + e.data.activeName + "].list", o.data.data), i)), "video" == e.data.titleArr[e.data.activeName].name && e.setData({
                        activitys1: [],
                        activitys2: [],
                        videoList: o.data.data
                    })) : wx.showToast({
                        icon: "none",
                        title: o.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {
                    console.log(t.msg);
                }
            });
        }
    },
    _getMoreData: function() {
        var e = this, i = {}, o = "", s = "";
        e.data.isLoadMore = !1, e.data.dataList[e.data.activeName].isLoadMore = !1, this.data.dataList[e.data.activeName].page >= this.data.dataList[e.data.activeName].total_page || (this.data.dataList[e.data.activeName].page = this.data.dataList[e.data.activeName].page + 1, 
        o = this.data.dataList[e.data.activeName].url, i = {
            member_id: this.data.id,
            page: this.data.dataList[e.data.activeName].page
        }, s = a.getNetAddresss(o), a._postNetWork({
            url: s,
            showToastIn: !1,
            data: i,
            success: function(a) {
                var i, o, s = a.data;
                1 == s.result ? e.setData((t(o = {
                    isLoadMore: !0,
                    showLoading: !0
                }, "dataList[" + e.data.activeName + "].isLoadMore", !0), t(o, "dataList[" + e.data.activeName + "].list", e.data.dataList[e.data.activeName].list.concat(s.data.data)), 
                o)) : e.setData((t(i = {}, "dataList[" + e.data.activeName + "].isLoadMore", !1), 
                t(i, "dataList[" + e.data.activeName + "].page", e.data.page - 1), i));
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    addNotice: function(e) {
        var i = this, o = e.currentTarget.dataset.notice, s = e.currentTarget.dataset.index, n = e.currentTarget.dataset.id, d = null;
        d = 1 == o ? "plugin.room.frontend.live-list.cancel-notice" : "plugin.room.frontend.live-list.play-notice";
        var r = a.getNetAddresss(d);
        a._postNetWork({
            url: r,
            showToastIn: !1,
            data: {
                id: n
            },
            success: function(a) {
                var e = a.data;
                1 == e.result ? 1 == o ? (i.setData(t({}, "roomList[" + s + "].notice", 0)), wx.showToast({
                    icon: "none",
                    title: "已取消提醒",
                    duration: 1500
                })) : (i.setData(t({}, "roomList[" + s + "].notice", 1)), wx.showToast({
                    icon: "none",
                    title: "已成功订阅",
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    goPlayBackData: function(t) {
        var a = t.currentTarget.dataset.roomid, e = t.currentTarget.dataset.backid;
        wx.navigateTo({
            url: "/packageD/directSeeding/livePage/livePage?id=" + a + "&playerType=video&backid=" + e + "&memberid=" + this.data.id
        });
    },
    onImageLoad: function(t) {
        for (var a = t.currentTarget.id, o = t.detail.width, s = t.detail.height, n = this.data.videoList, d = null, r = o / s, c = 0; c < n.length; c++) if (n[c].video_id == a) {
            d = n[c];
            break;
        }
        this.data.imgCount += 1;
        var l = this.data.activitys1, u = this.data.activitys2;
        e <= i ? (e += 176 / r + 60, l.push(d)) : (i += 176 / r + 60, u.push(d));
        var m = {
            activitys1: l,
            activitys2: u
        };
        this.data.imgCount >= this.data.videoList.length ? this.setData({
            showLoading: !0
        }) : this.setData({
            showLoading: !1
        }), this.setData(m);
    },
    toVideo: function(t) {
        var a = t.currentTarget.dataset.item, e = this.data.videoList.findIndex(function(t, e, i) {
            return t.video_id === a.video_id;
        });
        e = Math.ceil((e + 1) / 10), wx.navigateTo({
            url: "/packageC/video_goods/VideoDetail/VideoDetail?vid=" + a.video_id + "&page=" + e
        });
    }
});